import { createApp, nextTick,getCurrentInstance  } from "vue";
import { createPinia } from "pinia";
import ElementPlus from "element-plus";
import { ElMessage,ElMessageBox } from "element-plus";
import "element-plus/dist/index.css";

import zhCn from "element-plus/dist/locale/zh-cn.mjs";
import "./styles/global.less";
import App from "./App.vue";
import router from "./utils/permission";
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
import SeachTable from "@/components/SeachTable/index.vue";
import MessageBox from "@/components/MessageBox/index.vue";
import Modal from "@/components/Modal/index.vue";
import { createVersionPolling }  from "version-polling";
import "./styles/common.less";




const app = createApp(App);
createVersionPolling({
  pollingInterval: 3 * 1000,
  silent: import.meta.env.MODE === "development",
  onUpdate: (self) => {
    ElMessageBox({
      type: 'warning',
      title: '系统提示',
      showCancelButton: false,
      confirmButtonText:'确定',
      message:'系统已更新，请手动刷新页面！',
      beforeClose: async (action, instance, done) => {
        done()
      },
    })
  }
})
app.directive("selectClose", {
  mounted(el, binding) {
    nextTick(() => {
      el.addEventListener("mouseover", () => {
        nextTick(() => {
          $(
            '.el-select__caret svg path[d="m466.752 512-90.496-90.496a32 32 0 0 1 45.248-45.248L512 466.752l90.496-90.496a32 32 0 1 1 45.248 45.248L557.248 512l90.496 90.496a32 32 0 1 1-45.248 45.248L512 557.248l-90.496 90.496a32 32 0 0 1-45.248-45.248L466.752 512z"]'
          )
            .parent()
            .parent()
            .addClass("el-select-clear");
        });
      });
    });
  },
});


for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}
app.use(ElementPlus, {
  locale: zhCn,
});
app.use(createPinia());
app.use(router);

app
  .component("SeachTable", SeachTable)
  .component("MessageBox", MessageBox)
  .component("Modal", Modal);
app.config.globalProperties.$message = ElMessage;

app.mount("#app");
